import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const state = {
  num: 0
}
const getters = {
  getcatrnum: state => state.num
}
// 定义修改数据的函数
const mutations = {
  // 计算加入购物车的商品数量
  setcatrnum: (state, tonum) => {
    state.num = tonum
  },
  // 之前的数量
  totlennum: state => {
    let numList = JSON.parse(localStorage.getItem('cartinfo') || '[]')
    let totlenum = 0
    numList.map(itme => {
      if (itme.state) {
        totlenum += itme.cou
      }
    })
    state.num = totlenum
  }
}
const actions = {

}
export default new Vuex.Store({
  state,
  mutations,
  actions,
  getters
})
